<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="微博发布时间" prop="发布时间">
        <el-date-picker clearable
          v-model="queryParams.发布时间"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择微博发布时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="微博发布所在周" prop="week">
        <el-input
          v-model="queryParams.week"
          placeholder="请输入微博发布所在周"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="微博发布所在月" prop="month">
        <el-input
          v-model="queryParams.month"
          placeholder="请输入微博发布所在月"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="微博发布所在年" prop="year">
        <el-input
          v-model="queryParams.year"
          placeholder="请输入微博发布所在年"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:weibv3copy:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:weibv3copy:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:weibv3copy:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:weibv3copy:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getWeibv32"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="weibv3copyList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="记录ID" align="center" prop="id" />
      <el-table-column label="微博页码" align="center" prop="页码" />
      <el-table-column label="微博ID" align="center" prop="微博id" />
      <el-table-column label="微博作者" align="center" prop="微博作者" />
      <el-table-column label="微博发布时间" align="center" prop="发布时间" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.发布时间, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="微博内容" align="center" prop="微博内容" />
      <el-table-column label="微博转发数" align="center" prop="转发数" />
      <el-table-column label="微博评论数" align="center" prop="评论数" />
      <el-table-column label="微博点赞数" align="center" prop="点赞数" />
      <el-table-column label="微博发布设备" align="center" prop="发布于" />
      <el-table-column label="微博发布IP所属城市" align="center" prop="ip属地城市" />
      <el-table-column label="微博发布IP所属省份" align="center" prop="ip属地省份" />
      <el-table-column label="微博发布IP所属国家" align="center" prop="ip属地国家" />
      <el-table-column label="微博发布所在周" align="center" prop="week" />
      <el-table-column label="微博发布所在月" align="center" prop="month" />
      <el-table-column label="微博发布所在年" align="center" prop="year" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:weibv3copy:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:weibv3copy:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getWeibv32"
    />

    <!-- 添加或修改微博信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>



<script>
import { listWeibhtml, getWeibhtml, delWeibhtml, addWeibhtml, updateWeibhtml } from "@/api/system/weibhtml";

import { getWeibv32 } from "../../../api/system/weibv3";
// import { Base64 } from 'js-base64';
export default {
  name: "Weibhtml",
  data() {
    return {
      // 遮罩层
      urls: "",
      htmlText: "",
           // 遮罩层
           loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 微博信息表格数据
      weibv3copyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams2: {
        pageNum: 1,
        pageSize: 10,
        html: null
      },


      queryParams: {
        pageNum: 1,
        pageSize: 10,
        发布时间: null,
        week: null,
        month: null,
        year: null
      },

    
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getWeibv32();
  },
  methods: {
    /** 查询数据展示列表 */
    getList() {
      this.loading = true;
 
      listWeibhtml(this.queryParams2).then(response => {
        // this.weibhtmlList = response.rows;
        // console.log(response,"response")
        // this.total = response.total;
        // 取rows数组中最后一个
        response.rows.forEach((item,index)=>{
          if(index==response.rows.length-1){
         // 将 base64 为转换为字符串
        //将item.html字符串强转为 Base64 对象
         this.htmlText = this.Base64.decode(item.html)
         //将this.htmlText  转换为 v-html数据
         console.log(this.htmlText,"this.htmlText")
    
        var blob = new Blob([this.htmlText], {type: "text/plain;charset=utf-8"});
        console.log(blob,"blob")
        var url = window.URL.createObjectURL(blob);
        var a = document.createElement("a");
        a.href = url;
    
        console.log(url,"url")
        saveAs(blob, "test.html");
     
      
          }
        })
        // this.htmlText = response.rows[]
        this.loading = false;
      });
    },

    getWeibv32(){
      getWeibv32(this.queryParams).then(response => {
        this.weibv3copyList = response.rows;
        this.total = response.total;
        this.loading = false;
        console.log(response,"response2")
      })
    },
    // 取消按钮
   /** 查询微博信息列表 */
  //  getList() {
  //     this.loading = true;
  //     listWeibv3copy(this.queryParams).then(response => {
  //       this.weibv3copyList = response.rows;
  //       this.total = response.total;
  //       this.loading = false;
  //     });
  //   },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        页码: null,
        微博id: null,
        微博作者: null,
        发布时间: null,
        微博内容: null,
        转发数: null,
        评论数: null,
        点赞数: null,
        发布于: null,
        ip属地城市: null,
        ip属地省份: null,
        ip属地国家: null,
        week: null,
        month: null,
        year: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getWeibv32();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
  }
};
</script>
